using GrapeCity.Forguncy.CellTypes;
using GrapeCity.Forguncy.Plugin;
using PlugGraphVisVue;
using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace PlugGraphVisTree
{
    [Category("数据可视化")]
    [DependenceRuntimeModule("vue3")]
    [Icon("pack://application:,,,/PlugGraphVisTree;component/Resources/Icon.png")]
    [Designer("PlugGraphVisTree.Designer.PlugGraphVisTreeCellTypeDesigner, PlugGraphVisTree")]
    public class PlugGraphVisTreeCellType : CellType
    {
 

        public override string ToString()
        {
            return "数据可视化-树形结构图";
        }

        [DisplayName("授权License")]
        [Description("本机不影响使用。发布到服务器需要授权。联系QQ：31406724")]
        [FormulaProperty()]
        public object LicenseKey { get; set; } = "03003302R02P03002W03303703800Z02W03903303E02X03102P01E01C01E01D01D01D";

        [DisplayName("容器宽度")]
        [IntProperty(AllowNull = false)]
        [SupportModifyByRuntimeProperty(UseFormulaEditor = false)]
        private int ContentWidth { get; set; }

        [DisplayName("容器高度")]
        [IntProperty(AllowNull = false)]
        [SupportModifyByRuntimeProperty(UseFormulaEditor = false)]
        private int ContentHeight { get; set; }

        [DisplayName("画布背景色")]
        [ColorProperty(SupportTranslucency = false, SupportNoFill = true)]
        public string backgroundColor { get; set; } = "white";

        [DisplayName("画布工具条显示配置")]
        [Description("可以不设置")]
        [ObjectProperty(ObjType = typeof(ToolBarShowConfig))]
        public ToolBarShowConfig toolBarShowConfig { get; set; }

        [DisplayName("下载图片文字水印配置")]
        [Description("可以不设置")]
        [ObjectProperty(ObjType = typeof(TextWatermark))]
        public TextWatermark textWatermark { get; set; }

        [DisplayName("图的全局样式配置")]
        [Description("可以不设置，使用默认的节点样式、连线样式。")]
        [ObjectProperty(ObjType = typeof(GlobalConfig))]
        public GlobalConfig GraphVisGlobalConfig { get; set; }


        [DisplayName("树形结构根节点的标识")]
        [Description("根节点可能是空，也可能是0，根据实际情况填写。")]
        public string TreeRootFlag { get; set; }

        #region layout 默认布局配置
        [DisplayName("默认布局配置")]
        //[ComboProperty(ValueList = "fastForce|simulation|kawakai|hierarchical|concentric|circle|arf|tree|grid|dagre|radial|avoidlap", DisplayList = "快速网络布局|力导向布局|最优路径布局|层级布局|同心圆布局|环形布局|球面引力布局|树形布局|网格布局|流向布局|中心径向布局|避免重叠")]
        [ComboProperty(ValueList = "tree", DisplayList = "树形布局")]
        public  string layout { get; set; } = "tree";



        [ObjectProperty(ObjType = typeof(Layout_FastForce), IndentLevel = 2)]
        [DisplayName("快速网络布局")]
        public Layout_FastForce layout_fastForce { get; set; }

        [ObjectProperty(ObjType = typeof(Layout_Simulation), IndentLevel = 2)]
        [DisplayName("力导向布局")]
        public Layout_Simulation layout_simulation { get; set; }

        [ObjectProperty(ObjType = typeof(Layout_Kawakai), IndentLevel = 2)]
        [DisplayName("最优路径布局")]
        public Layout_Kawakai layout_kawakai { get; set; }


        [ObjectProperty(ObjType = typeof(Layout_Hierarchical), IndentLevel = 2)]
        [DisplayName("层级布局")]
        public Layout_Hierarchical layout_hierarchical { get; set; }

        [ObjectProperty(ObjType = typeof(Layout_Concentric), IndentLevel = 2)]
        [DisplayName("同心圆布局")]
        public Layout_Concentric layout_concentric { get; set; }


        [ObjectProperty(ObjType = typeof(Layout_Circle), IndentLevel = 2)]
        [DisplayName("环形布局")]
        public Layout_Circle layout_circle { get; set; }


        [ObjectProperty(ObjType = typeof(Layout_Arf), IndentLevel = 2)]
        [DisplayName("球面引力布局")]
        public Layout_Arf layout_arf { get; set; }



        [ObjectProperty(ObjType = typeof(Layout_Tree), IndentLevel = 2)]
        [DisplayName("树形布局")]
        public Layout_Tree layout_tree { get; set; }


        [ObjectProperty(ObjType = typeof(Layout_Grid), IndentLevel = 2)]
        [DisplayName("网格布局")]
        public Layout_Grid layout_grid { get; set; }

        [ObjectProperty(ObjType = typeof(Layout_Dagre), IndentLevel = 2)]
        [DisplayName("流向布局")]
        public Layout_Dagre layout_dagre { get; set; }

        [ObjectProperty(ObjType = typeof(Layout_Radial), IndentLevel = 2)]
        [DisplayName("中心径向布局")]
        public Layout_Radial layout_radial { get; set; }

        [ObjectProperty(ObjType = typeof(Layout_Avoidlap), IndentLevel = 2)]
        [DisplayName("避免重叠")]
        public Layout_Avoidlap layout_avoidlap { get; set; }
        #endregion

        [DisplayName("数据源选择")]
        //[RadioGroupProperty(ValueList = "demo_tree01|demo_tree02|demo_tree03|config|database_tree", DisplayList = "演示数据-新员工入职|演示数据-智能问答|演示数据-冰桶挑战|配置|数据库(树形表)")]
        [RadioGroupProperty(ValueList = "demo_tree01|demo_tree02|demo_tree03|config|database_tree", DisplayList = "演示数据-新员工入职|演示数据-智能问答|演示数据-冰桶挑战|节点配置(树形结构)|数据库(树形表)")]
        public string SourceDataFrom { get; set; } = "demo_tree01";


        [ListProperty(IndentLevel = 2)]
        [DisplayName("节点配置")]
        public List<TreeNode> SourceDataFromConfig_NodeList { get; set; } = new List<TreeNode>();



        [BindingDataSourceProperty(Columns = "nodeid|label|type|image|tags|tagColor", ColumnsDescription = "nodeid:唯一节点ID|label:节点文本|image:节点url图片|type:连接类型|tags:角标的值|tagColor:角标的颜色", IndentLevel = 2)]
        [DisplayName("绑定 节点 数据源")]
        [Description("从数据库生成节点信息")]
        public object SourceDataFromDB_Node { get; set; }


        [ListProperty(IndentLevel = 2)]
        [DisplayName("连线配置")]
        private List<Link> SourceDataFromConfig_LinkList { get; set; } = new List<Link>();

        [BindingDataSourceProperty(Columns = "linkid|source|target|label|type", ColumnsDescription = "linkid:唯一连接ID|source:源节点ID|target:目标节点ID|label:连接文本|type:连接类型", IndentLevel = 2)]
        [DisplayName("绑定 连线 数据源")]
        [Description("从数据库生成节点之间的连线信息")]
        public object SourceDataFromDB_Link { get; set; }



        [BindingDataSourceProperty(Columns = "nodeid|label|linklabel|type|tags|nodeParentID", ColumnsDescription = "nodeid:唯一节点ID|label:节点文本|linklabel:连线文本|type:节点类型|tags:节点标签|nodeParentID:父节点ID", IndentLevel = 2,
                                  IsIdPidStructure = true, TreeIdColumnName = "nodeid", TreePidColumnName = "nodeParentID", AllowAddCustomColumns = true)]
        [DisplayName("绑定 树形表")]
        [Description("从树形表生成节点信息,连线信息")]
        public object SourceDataFromDB_Tree { get; set; }


        [DisplayName("单个节点样式配置")]
        [Description("对某个节点单独设置样式，优先级大于全局样式配置。")]
        [ObjectListProperty(ItemType = typeof(SingleNodeStyle), DefaultName = "节点样式配置", IndentLevel = 2)]
        public List<INamedObject> SingleNodeStyleConfig { get; set; }

        [DisplayName("单个连线样式配置")]
        [Description("对某个连线单独设置样式，优先级大于全局样式配置。")]
        [ObjectListProperty(ItemType = typeof(SingleLinkStyle), DefaultName = "连线样式配置", IndentLevel = 2)]
        public List<INamedObject> SingleLinkStyleConfig { get; set; }

        [DisplayName("节点右键命令")]
        [ObjectProperty(ObjType = typeof(NodeRightClick))]
        public NodeRightClick NodeRightClickCommand { get; set; }

        [DisplayName("连线右键命令")]
        [ObjectProperty(ObjType = typeof(LinkRightClick))]
        public LinkRightClick LinkRightClickCommand { get; set; }

        [RunTimeMethod]
        private void updateGraphData(string graphvis_data)
        {
        }


        [DisplayName("设置画布尺寸")]
        [Description("指定宽高，才需要设定宽度、高度。")]
        [RunTimeMethod]
        public void setCavasSize(
            [ComboProperty(ValueList = "auto|specific|fixContent",DisplayList ="自适应(宽高都是100%)|指定宽高|画布适应内容大小")]
             string param_type,
            [ItemDisplayName("宽度")]
            int param_width,
            [ItemDisplayName("高度")]
            int param_height)
        {

        }
        [DisplayName("获取画本尺寸")]
        [RunTimeMethod]
        public CavasSize getCavasSize()
        {
            return null;
        }

        #region GetDesignerPropertyVisible
        public override bool GetDesignerPropertyVisible(string propertyName)
        {
            if (propertyName == nameof(SourceDataFromConfig_NodeList)
                || propertyName == nameof(SourceDataFromConfig_LinkList))
            {
                if (SourceDataFrom == "config")
                {
                    return true;
                }
                else
                {
                    return false;
                }

            }
            else if (propertyName == nameof(SourceDataFromDB_Node)
                || propertyName == nameof(SourceDataFromDB_Link))
            {
                if (SourceDataFrom == "database")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else if (propertyName == nameof(SingleNodeStyleConfig)
                || propertyName == nameof(SingleLinkStyleConfig))
            {
                if (SourceDataFrom == "database")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else if (propertyName == nameof(SourceDataFromDB_Tree))//
            {
                if (SourceDataFrom == "database_tree")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            #region  布局选择联动显示

            else if (propertyName == nameof(layout_fastForce))
            {
                if (layout == "fastForce") { return true; } else { return false; }
            }
            else if (propertyName == nameof(layout_simulation))
            {
                if (layout == "simulation") { return true; } else { return false; }
            }
            else if (propertyName == nameof(layout_kawakai))
            {
                if (layout == "kawakai") { return true; } else { return false; }
            }
            else if (propertyName == nameof(layout_hierarchical))
            {
                if (layout == "hierarchical") { return true; } else { return false; }
            }
            else if (propertyName == nameof(layout_concentric))
            {
                if (layout == "concentric") { return true; } else { return false; }
            }
            else if (propertyName == nameof(layout_circle))
            {
                if (layout == "circle") { return true; } else { return false; }
            }
            else if (propertyName == nameof(layout_arf))
            {
                if (layout == "arf") { return true; } else { return false; }
            }
            else if (propertyName == nameof(layout_tree))
            {
                if (layout == "tree") { return true; } else { return false; }
            }
            else if (propertyName == nameof(layout_grid))
            {
                if (layout == "grid") { return true; } else { return false; }
            }
            else if (propertyName == nameof(layout_dagre))
            {
                if (layout == "dagre") { return true; } else { return false; }
            }
            else if (propertyName == nameof(layout_radial))
            {
                if (layout == "radial") { return true; } else { return false; }
            }
            else if (propertyName == nameof(layout_avoidlap))
            {
                if (layout == "avoidlap") { return true; } else { return false; }
            }

            #endregion
            return base.GetDesignerPropertyVisible(propertyName);
        }

        #endregion


    }

    public class CavasSize
    {
        public int Width { get; set; }
        public int Height { get; set; }
    }

}
